<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title></title>
    <!-- 引入layui 样式-->
    <link rel="stylesheet" href="../../static/css/style.css"/>
    <link rel="stylesheet" href="../../static/layer/css/layui.css"/>
    <link rel="stylesheet" href="../../static/css/font-awesome.min.css">
    <link rel="stylesheet" href="../../static/ucss/contract/contract.css"/>
    <script type="text/javascript" src="../../static/layer/layui.js"></script>
    <style>
        .blockquote-bottom {
            width: 100%;
            position: fixed;
            margin: 0;
            bottom: 0;
            left: 0;
            text-align: center;
            background-color: #ffffff;
            border-top: 1px solid #f4f4f4;
            z-index: 2;
        }
        .blockquote-bottom-item {
            margin: 15px 0;
        }
    </style>
</head>
<body>
<form class="layui-form" action="">
    <input id="id" name="ID" type="hidden"/>
    <div class="layui-tab layui-tab-brief" lay-filter="contractInfoTabBrief">
        <div class="layui-tab-content">
            <div class="tab-body">
                <div>
                    <div class="quote-housing-info">
                        <div class="quote-title" style="margin-bottom: 20px;">
                            <i class="fa fa-circle-o" aria-hidden="true"></i>
                            <span>承租人信息</span>
                        </div>
                        <div class="layui-form-item">
                            <div class="room-box-arr clone-box-container">
                                <div class="layui-col-xs6">
                                    <label class="layui-form-label" id="gongsi">公司名称:</label>
                                    <div class="layui-input-inline" style=" width: 255px;">
                                        <input type="text" name="COMPANY_NAME" lay-verify="" autocomplete="off"
                                               class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-col-xs6">
                                    <div class="layui-inline">
                                        <label class="layui-form-label">行业:</label>
                                        <div class="layui-input-inline" style=" width: 255px;">
                                            <select name="INDUSTRY_ID" lay-verify="required" id="TRADE1" lay-search="">
                                                <option value="">请选择行业</option>
                                            </select>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-col-xs6">
                                <div class="layui-inline">
                                <label class="layui-form-label" id="gongsi1">商户别名:</label>
                                <div class="layui-input-inline" style=" width: 255px;">
                                    <input type="text" name="BYNAME" lay-verify="" autocomplete="off" class="layui-input">
                                </div>
                                </div>
                        </div>
                            <div class="layui-col-xs6">
                                <label class="layui-form-label" id="sfzh">执照编号:</label>
                                <div class="layui-input-inline" style=" width: 255px;">
                                    <input type="text" name="BUSINESS_LICENSE" lay-verify="" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item faren">
                            <div class="layui-col-xs6">
                                <label class="layui-form-label">法人姓名:</label>
                                <div class="layui-input-inline" style=" width: 255px;">
                                    <input type="text" name="LEGAL_PERSON_NAME" lay-verify="" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-col-xs6">
                                <label class="layui-form-label">联系方式:</label>
                                <div class="layui-input-inline" style=" width: 255px;">
                                    <input type="text" name="LEGAL_PERSON_TEL" lay-verify="" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-col-xs6">
                                <label class="layui-form-label">签订人:</label>
                                <div class="layui-input-inline" style=" width: 255px;">
                                    <input type="text" name="SIGNER" lay-verify="" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-col-xs6">
                                <label class="layui-form-label">联系方式:</label>
                                <div class="layui-input-inline" style=" width: 255px;">
                                    <input type="text" name="SIGNER_TEL" lay-verify="" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-col-xs6">
                                <label class="layui-form-label">通讯地址:</label>
                                <div class="layui-input-inline" style=" width: 255px;">
                                    <input type="text" name="CONTRACT_ADDRESS" lay-verify="" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    </div>
    </div>
    <div class="layui-form-item blockquote-bottom">
        <div class="blockquote-bottom-item">
            <button class="layui-btn layui-btn-small" lay-filter="demo1"  lay-submit="">提交</button>
            <button type="reset" class="layui-btn-small layui-btn-primary">重置</button>
        </div>
    </div>
</form>
</body>
<script type="text/javascript" src="../../static/js/common/dateUtils.js"></script>
<script type="text/javascript" src="../../static/js/common/queryUtils.js"></script>
<script>
    // 加载元素控件
    var $, element, layer, laydate, form;
    layui.use(['jquery', 'table','element', 'layer', 'laydate', 'form', 'upload'], function () {
        // 加载元素控件
        $ = layui.jquery, element = layui.element, layer = layui.layer, laydate = layui.laydate, form = layui.form;
        var customerid = QueryUtils.GetQueryString("id");
        var operateType = QueryUtils.GetQueryString("type");
        var lease = QueryUtils.GetQueryString("lease");
        var detaildictionaryid;
        var editdictionaryid;
        $("#id").val(customerid);
        switch (operateType) {
            case "detail":
                $.ajax({
                    url: "/customer/infotenant",
                    data: {ID:customerid},
                    dataType: "json",
                    type: "post",
                    async: false,
                    success: function (res) {
                        if (res.errcode === "0") {
                            $("input[name='COMPANY_NAME']").val(res.data.COMPANY_NAME);
                            $("input[name='BYNAME']").val(res.data.BYNAME);
                            $("input[name='BUSINESS_LICENSE']").val(res.data.BUSINESS_LICENSE);
                            $("input[name='LEGAL_PERSON_NAME']").val(res.data.LEGAL_PERSON_NAME);
                            $("input[name='LEGAL_PERSON_TEL']").val(res.data.LEGAL_PERSON_TEL);
                            $("input[name='CONTRACT_ADDRESS']").val(res.data.CONTRACT_ADDRESS);
                            $("input[name='SIGNER']").val(res.data.SIGNER);
                            $("input[name='SIGNER_TEL']").val(res.data.SIGNER_TEL);
                            /*form.render("radio");*/
                            $("input").attr("disabled","disabled");
                            detaildictionaryid = res.data.INDUSTRY_ID;
                        } else if (res.errcode === "1"){
                            layer.msg(res.errmsg, function(){});
                        }
                    },
                    error: function(XMLHttpRequest, textStatus, errorThrown) {
                        console.error(XMLHttpRequest.status);
                        console.error(XMLHttpRequest.readyState);
                        console.error(textStatus);
                    }
                });
                $.ajax({
                    url: "/customer/listdictionary",
                    dataType: "json",
                    type: "post",
                    async: false,
                    success: function (res) {
                        if (res.errcode === "0") {
                            for(var i=0;i<res.data.length;i++){
                                if(res.data[i].ID==detaildictionaryid){
                                    $("select[name='INDUSTRY_ID']").append('<option value="' + res.data[i].ID + '" selected>' + res.data[i].NAME +'</option>');
                                }else {
                                    $("select[name='INDUSTRY_ID']").append('<option value="' + res.data[i].ID + '">' + res.data[i].NAME +'</option>');
                                }
                            }
                            form.render("select");
                            $("select[name='INDUSTRY_ID']").attr("disabled","disabled");
                            $("button").attr("disabled","true");

                        } else if (res.errcode === "1"){
                            layer.msg(res.errmsg, function(){});
                        }
                    },
                    error: function(XMLHttpRequest, textStatus, errorThrown) {
                        console.error(XMLHttpRequest.status);
                        console.error(XMLHttpRequest.readyState);
                        console.error(textStatus);
                    }
                });
                break;
            case "edit":
                if (lease == "1") {
                    $("#gongsi").html("姓名:");
                    $("#sfzh").html("身份证号:");
                    $(".faren").hide();
                }
                $.ajax({
                    url: "/customer/infotenant",
                    data: {ID:customerid},
                    dataType: "json",
                    type: "post",
                    async: false,
                    success: function (res) {
                        if (res.errcode === "0") {
                            $("input[name='COMPANY_NAME']").val(res.data.COMPANY_NAME);
                            $("input[name='BYNAME']").val(res.data.BYNAME);
                            $("input[name='BUSINESS_LICENSE']").val(res.data.BUSINESS_LICENSE);
                            $("input[name='LEGAL_PERSON_NAME']").val(res.data.LEGAL_PERSON_NAME);
                            $("input[name='LEGAL_PERSON_TEL']").val(res.data.LEGAL_PERSON_TEL);
                            $("input[name='CONTRACT_ADDRESS']").val(res.data.CONTRACT_ADDRESS);
                            $("input[name='SIGNER']").val(res.data.SIGNER);
                            $("input[name='SIGNER_TEL']").val(res.data.SIGNER_TEL);
                            /*form.render("radio");*/
                            editdictionaryid = res.data.INDUSTRY_ID;
                        } else if (res.errcode === "1"){
                            layer.msg(res.errmsg, function(){});
                        }
                    },
                    error: function(XMLHttpRequest, textStatus, errorThrown) {
                        console.error(XMLHttpRequest.status);
                        console.error(XMLHttpRequest.readyState);
                        console.error(textStatus);
                    }
                });
                $.ajax({
                    url: "/customer/listdictionary",
                    dataType: "json",
                    type: "post",
                    async: false,
                    success: function (res) {
                        if (res.errcode === "0") {
                            for(var i=0;i<res.data.length;i++){
                                if(res.data[i].ID==editdictionaryid){
                                    $("select[name='INDUSTRY_ID']").append('<option value="' + res.data[i].ID + '" selected>' + res.data[i].NAME +'</option>');
                                }else {
                                    $("select[name='INDUSTRY_ID']").append('<option value="' + res.data[i].ID + '">' + res.data[i].NAME +'</option>');
                                }
                            }
                            form.render("select");
                        } else if (res.errcode === "1"){
                            layer.msg(res.errmsg, function(){});
                        }
                    },
                    error: function(XMLHttpRequest, textStatus, errorThrown) {
                        console.error(XMLHttpRequest.status);
                        console.error(XMLHttpRequest.readyState);
                        console.error(textStatus);
                    }
                });
                break;
            }
        //监听提交
        form.on('submit(demo1)', function(data){
            /* console.log(data.field);*/
            var data1=data.field;
            /*console.log(data1);*/
            layer.msg('确认修改客户吗', {
                time: 0
                , btn: ['确定', '取消']
                , shade: 0.3
                , yes: function (data) {
                    $.ajax({
                        url: "/customer/edittenant",
                        data: data1,
                        type: "Post",
                        dataType: "json",
                        async: false,
                        success: function (res) {
                            if (res.errcode === "0") {
                                var index = parent.layer.getFrameIndex(window.name); // 先得到当前iframe层的索引
                                parent.layer.close(index); // 再执行关闭
                                // window.parent.location.reload();
                                window.parent.layui.table.reload("zhgl",{});
                                layer.msg("保存成功");
                            }
                        }
                    });
                },
            })
            return false;
        });
    });
    var change = {
    }
    var operate = {
    }
</script>
</html>